package org.example.spring.ioc.bean;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import lombok.Data;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

@Data
public class User implements InitializingBean, DisposableBean {
    private String name;
    private String password;

    private Car car;

    @Autowired
    public void setCar(Car car) {
        System.out.println("User=======>setCar  @Autowired注解指定的属性自动注入"+ car);
        this.car = car;
    }

    public User () {
        System.out.println("User=======>User的无参构造");
    }

    //BeanPostProcessor:理解后置处理器机制（Bean的外挂处理

    //理解构造器后置处理钩子@PostConstruct
    @PostConstruct
    public void postConstruct() {
        System.out.println("User=======>postConstruct  @PostConstruct注解指定的构造器后置处理钩子");
    }

    //理解销毁预处理钩子@PreDestroy
    @PreDestroy
    public void preDestroy() {
        System.out.println("User=======>preDestroy  @PreDestroy注解指定的销毁预处理钩子");
    }

    //    Bean.class中：
//    String initMethod() default "";
//    String destroyMethod() default "(inferred)";

    public void init() {
        System.out.println("User=======>init  @Bean注解指定的初始化");
    }

    public void dest() {
        System.out.println("User=======>destroy  @Bean注解指定的摧毁");
    }

    //属性设置之后进行调用，set赋值完成之后
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("User=======>afterPropertiesSet  通过InitializingBean调用实现  @Bean注解指定的属性设置完成之后调用");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("User=======>destroy  通过DisposableBean调用实现  @Bean注解指定的摧毁完成之前调用");
    }

}
